package com.heima.minio.controller;

import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.PutObjectArgs;
import io.minio.errors.*;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class MinIOTest {

    public static void main(String[] args) throws Exception{
        /*
        FileInputStream fileInputStream = null;
        try {
            fileInputStream =  new FileInputStream("E:\\leadnewshtml\\list.html");
            //1.创建minio链接客户端
            MinioClient minioClient = MinioClient.builder()
                    .credentials("minio", "minio123")
                    .endpoint("http://192.168.56.136:9000").build();
            //2.上传
            PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                    .object("list.html")//文件名
                    .contentType("text/html")//文件类型
                    .bucket("leadnews")//桶名词  与minio创建的名词一致
                    .stream(fileInputStream, fileInputStream.available(), -1) //文件流
                    .build();
            minioClient.putObject(putObjectArgs);
            System.out.println("http://192.168.56.136:9000/leadnews/ak47.jpg");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
         */

        try {
            FileInputStream fileInputStream = null;
            fileInputStream = new FileInputStream("E:\\leadnewshtml\\list.html");
            //1.创建minio链接客户端
            MinioClient build = MinioClient.builder()
                    .credentials("minio", "minio123")
                    .endpoint("http://192.168.56.136:9000")
                    .build();
            // 上传
            PutObjectArgs leadnews = PutObjectArgs.builder().object("lists.html")
                    .contentType("text/html")
                    .bucket("leadnews")
                    .stream(fileInputStream, fileInputStream.available(), -1).build();
            ObjectWriteResponse response = build.putObject(leadnews);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}